<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>用户管理</title>
	<%@include file="/WEB-INF/views/include/head.jsp" %>
	<%@include file="/WEB-INF/views/include/treetable.jsp" %>
	<style type="text/css">
		.jqGrid_wrapper{padding:0;margin-top:2px;}
		
	</style>
	<script type="text/javascript">
		$(document).ready(function() {
			initGrid();
		});
	
	    function initGrid(){
	    	height=defaultHeight>600?(defaultHeight*0.76):(defaultHeight*0.665);
			if(isIE)height=height-5;
	    	$("#jqGrid").jqGrid({
                url: '${ctxAdmin}/sys/user/loadData?officeId=${officeId}',
                mtype: "POST",
                datatype: "json",
                responsive:true,
                page: 1,
                colModel: [
					{ label: 'id', name: 'id', key: true, hidden:true},   
					{ label: '用户名称', name: 'name',index:'a.name',width: 60},
                    { label:'登录名',name:'loginName',index:'a.login_name',width:50},
                    { label: '所属机构', name: 'office.name',index: 'o.name',width:60},
                    {label:'负责人',name:'master',index:'a.master',width:80},
                    { label: '手机', name: 'mobile',index:'a.mobile', width: 50 },
                    {label:'操作',name:'cz',search:false,sortable:false,title:false,formatter:czFmt,width:70,align:'center'}
                ],
				viewrecords: true,
                height: height,
                rowNum: 10,
                rowList:[10,20,30],
                loadonce:false,
                multiselect: true, // 显示多选复选框
                autowidth: true,
                pager: "#jqGridPager"
            });
// 			$('#jqGrid').jqGrid('filterToolbar',{stringResult:true, searchOnEnter:true, defaultSearch:'cn'});
			$('#jqGrid').jqGrid('navGrid','#jqGridPager',{edit:false,add:false,del:false,search:false});
	    	//$(window).bind("resize",function(){var width=$(".jqGrid_wrapper").width();$("#jqGrid").setGridWidth(width);});
	    }
	    /*格式化操作栏*/
	    function czFmt(c,o,r){
			var res='';
			var id=r.id;
			var loginName=r.loginName;
			 
			//<shiro:hasPermission name="sys:user:edit">';
			res='<a class="btn-success btn-sm" href="${ctxAdmin}/sys/user/form?id='+id+'">修改</a>&nbsp;';
			//<c:if test="${roleCode == 'admin'}">
			res+='<a class="btn-danger btn-sm" href="javascript:void(0)" onclick="resetPwd(\''+id+'\',\''+loginName+'\')">重置密码</a>&nbsp;';
			//</c:if>
			//<c:if test="${roleCode == 'admin'}">
			res+='<a class="btn-danger btn-sm" href="javascript:void(0)" onclick="ensure(\''+id+'\')">删除</a>';
			//</c:if>
			//</shiro:hasPermission>;
			return res;
		}
	
		function ensure(id){
		

			confirmx('你确定要删除此数据吗？',null,function(){
					$.ajax({
					url:'${ctxAdmin}/sys/user/delete',
					type:'post',
					dataType:'json',
					data:{id:id},
					success:function(res){
					var code = res.code;
					var message = res.message;				
					layer.msg(message);
					$('#jqGrid').trigger("reloadGrid");
					}
				});}		
			);
				
		}

		function deleteDataBatch(ids){
			var _ids=$('#jqGrid').jqGrid('getGridParam','selarrrow');
			if(_ids.length==0){
			layer.msg("请选择要操作的行！");
			return
			}
			var ids = _ids.join(",");
			confirmx('你确定要删除此数据吗？',null,function(){
					$.ajax({
					url:'${ctxAdmin}/sys/user/delete',
					type:'post',
					dataType:'json',
					data:{id:ids},
					success:function(res){
					var code = res.code;
					var message = res.message;				
					layer.msg(message);
					$('#jqGrid').trigger("reloadGrid");
					}
				});}		
			);
	
				
			}
		/*确认提示*/
		function resetPwd(id,loginName){
		


			confirmx('要重置该用户密码吗？',{title:'密码重置',shade:0.1},function(){
					$.ajax({
					url:'${ctxAdmin}/sys/user/resetPwd',
					type:'post',
					dataType:'json',
					data:{id:id},
					success:function(res){
					var code = res.code;
					var message = res.message;				
					layer.msg(message);
					$('#jqGrid').trigger("reloadGrid");
					}
				});}		
			);
				
			
		}
		$(function() {
			$('#btnSubmit').click(function() {
				var name = $("#name").val();
				var loginName = $("#loginName").val();
				$('#jqGrid').jqGrid('setGridParam', {
					datatype : 'json',
					postData : {
						'name' : name,
						'loginName' : loginName
					}
				}).trigger("reloadGrid");
			});
		});
	</script>
</head>
<body>
	<body>
	<sys:message content="${message}"/>
	<form action="" id="searchForm" method="post" style="display: none"></form>
	<ul id="navlist" class="nav nav-tabs">
		<li class="active"><a href="${ctxAdmin}/sys/user/list">用户列表</a></li>
		<c:if test="${roleCode != 'crest'}">
		<shiro:hasPermission name="sys:user:edit"><li><a href="${ctxAdmin}/sys/user/form">添加用户</a></li></shiro:hasPermission>
		</c:if>
	</ul>
	<div class="jqGrid_wrapper">
		<div class="search_row">
		<form id="myForm">
			<label class="col-sm-1">用户名称：</label>
			<div class="col-sm-2">
			<input id="name" name="name" type="text" class="form-control ipt-search" />
			</div>
			
			<label class="col-sm-1">登录名：</label>
			<div class="col-sm-2">
			<input id="loginName" name="loginName" type="text" class="form-control ipt-search"/>
			</div>
			

			
			<div class="col-sm-search">
			&nbsp;<input id="btnSubmit" class="btn btn-sm btn-success" type="button"  value="查询" />
			&nbsp; <input id="btnReset" class="btn btn-sm btn-danger" type="button" value="重 置" />
			<shiro:hasPermission name="sys:user:edit">
			 &nbsp;<input id="btnDelete" class="btn btn-sm btn-danger" type="button" onclick="deleteDataBatch()" value="批量删除" />
			</shiro:hasPermission>
			</div>	
		</form>		
		</div>
		<div class="search_row_split"></div>
		 <table id="jqGrid"></table>
		 <div id="jqGridPager"></div>
	</div>
</body>
</html>